package cn.yunyichina.provider.logs.thread;


import cn.yunyichina.provider.logs.LogApp;
import cn.yunyichina.utils.commons.IDUtils;
import cn.yunyichina.utils.log.Log;
import cn.yunyichina.utils.log.constant.LogScene;
import com.alibaba.ttl.TransmittableThreadLocal;
import com.alibaba.ttl.threadpool.TtlExecutors;
import org.slf4j.MDC;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by kevin on 2017/12/14.
 */
public class TestMdc implements Runnable {

    public   static ExecutorService executorService = Executors.newFixedThreadPool(1);
    public static ExecutorService executorService2 = TtlExecutors.getTtlExecutorService(executorService);

    public static InheritableThreadLocal<String> mythreadNumber=new InheritableThreadLocal<>();

    public static  TransmittableThreadLocal<String> myparent = new TransmittableThreadLocal<String>();
    public static  TransmittableThreadLocal<Integer> myparent2 = new TransmittableThreadLocal<Integer>();
    public static  TransmittableThreadLocal<Long> myparent3 = new TransmittableThreadLocal<Long>();

    @Override
    public void run() {
        String id=IDUtils.getRandomUUID32();
        Log.i(LogScene.BED,"当前主线程:"+Thread.currentThread().getName()+"开始设置id:"+id);

        mythreadNumber.set(id);
        MDC.put("traceId",id);
//        myparent.set(id);
//        myparent2.set(1);
//        myparent3.set(7890L);
        executorService2.execute(new TestThreadPool());
//        Thread thread=new Thread(new TestThreadPool());
//        thread.start();
    }

}
